<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no" />
    <meta name="renderer" content="webkit" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <link rel="apple-touch-icon" href="./src/icon.png" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <link rel="icon" type="image/png" href="./src/icon.png">
    <title>查询历史 - 光遇身高查询</title>
    <style>
        :root {
            /* Apple Design System Colors */
            --primary: #0A84FF;
            --secondary: #5E5CE6;
            --accent: #FF9F0A;
            --background: #000000;
            --elevated-background: rgba(28, 28, 30, 0.92);
            --card-background: rgba(44, 44, 46, 0.8);
            --border: rgba(84, 84, 88, 0.65);
            --text-primary: #FFFFFF;
            --text-secondary: rgba(235, 235, 245, 0.6);
            --text-tertiary: rgba(235, 235, 245, 0.3);
            
            /* Shadows and Effects */
            --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
            --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
            --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
            --blur-background: saturate(180%) blur(20px);
            
            /* Animation */
            --transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
            
            /* Typography */
            --system-font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', system-ui, sans-serif;
            --radius-base: 10px;
            --radius-lg: 14px;
            --spacing-base: 16px;
        }

        body {
            margin: 0;
            padding: 0;
            background: var(--background);
            color: var(--text-primary);
            font-family: var(--system-font);
            line-height: 1.5;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }

        .app-container {
            min-height: 100vh;
            display: grid;
            grid-template-rows: auto 1fr;
            background: var(--elevated-background);
            backdrop-filter: var(--blur-background);
            -webkit-backdrop-filter: var(--blur-background);
        }

        .header {
            padding: var(--spacing-base) 0;
            background: var(--card-background);
            backdrop-filter: var(--blur-background);
            -webkit-backdrop-filter: var(--blur-background);
            border-bottom: 0.5px solid var(--border);
        }

        .header-content {
            max-width: 600px;
            margin: 0 auto;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: calc(var(--spacing-base) * 1.25);
            padding: 0 var(--spacing-base);
        }

        .header-buttons {
            display: flex;
            gap: 16px;
            margin-top: 8px;
        }

        .join-group-btn {
            background: var(--primary);
            color: var(--text-primary);
            text-decoration: none;
            padding: 12px 20px;
            border-radius: var(--radius-base);
            font-weight: 600;
            font-size: 15px;
            transition: var(--transition);
            border: none;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 6px;
            letter-spacing: -0.022em;
        }

        .join-group-btn:hover {
            transform: translateY(-1px);
            filter: brightness(1.1);
        }

        .join-group-btn:active {
            transform: translateY(0);
        }

        .logo {
            font-size: 17px;
            font-weight: 600;
            color: var(--text-primary);
            text-decoration: none;
            display: flex;
            align-items: center;
            gap: 8px;
            letter-spacing: -0.022em;
        }

        .page-title {
            font-size: 34px;
            font-weight: 700;
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            -webkit-background-clip: text;
            background-clip: text;
            -webkit-text-fill-color: transparent;
            margin: 0;
            text-align: center;
            letter-spacing: -0.03em;
        }

        .main-content {
            width: 100%;
            max-width: 600px;
            margin: 0 auto;
            padding: var(--spacing-base);
            display: flex;
            flex-direction: column;
            gap: var(--spacing-base);
            box-sizing: border-box;
        }

        .search-section,
        .history-section {
            width: 100%;
            background: var(--card-background);
            border-radius: var(--radius-lg);
            border: 0.5px solid var(--border);
            backdrop-filter: var(--blur-background);
            -webkit-backdrop-filter: var(--blur-background);
            box-sizing: border-box;
            padding: var(--spacing-base);
        }

        .search-input-container {
            width: 100%;
            margin-bottom: var(--spacing-base);
            box-sizing: border-box;
        }

        .search-input {
            width: 100%;
            height: 38px;
            background: rgba(255, 255, 255, 0.08);
            border: 1px solid var(--border);
            border-radius: var(--radius-base);
            padding: 0 16px;
            color: var(--text-primary);
            font-family: var(--system-font);
            font-size: 15px;
            letter-spacing: -0.022em;
            outline: none;
            transition: var(--transition);
            box-sizing: border-box;
        }

        .search-input:focus {
            background: rgba(255, 255, 255, 0.12);
            border-color: var(--primary);
        }

        .search-input::placeholder {
            color: var(--text-secondary);
        }

        .history-tabs {
            width: 100%;
            display: flex;
            gap: 4px;
            margin-bottom: var(--spacing-base);
            padding: 2px;
            background: rgba(255, 255, 255, 0.08);
            border-radius: var(--radius-base);
            box-sizing: border-box;
        }

        .tab-button {
            background: none;
            border: none;
            color: var(--text-primary);
            cursor: pointer;
            padding: 8px 16px;
            border-radius: 8px;
            font-size: 14px;
            font-weight: 500;
            letter-spacing: -0.022em;
            flex: 1;
            text-align: center;
            white-space: nowrap;
            min-width: 0;
            transition: var(--transition);
        }

        .tab-button.active {
            background: var(--primary);
            font-weight: 600;
        }

        .tab-button:hover:not(.active) {
            background: rgba(255, 255, 255, 0.12);
        }

        .history-list {
            width: 100%;
            display: flex;
            flex-direction: column;
            gap: var(--spacing-base);
            box-sizing: border-box;
        }

        .history-item,
        .empty-state {
            width: 100%;
            background: rgba(255, 255, 255, 0.08);
            border-radius: var(--radius-base);
            border: 0.5px solid var(--border);
            padding: calc(var(--spacing-base) * 0.75);
            box-sizing: border-box;
            min-height: 120px;
            display: flex;
            flex-direction: column;
        }

        .empty-state {
            align-items: center;
            justify-content: center;
            text-align: center;
            color: var(--text-secondary);
            font-size: 15px;
            letter-spacing: -0.022em;
        }

        .history-item:hover {
            background: rgba(255, 255, 255, 0.12);
            transform: translateY(-1px);
        }

        .history-item-header {
            width: 100%;
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: var(--spacing-base);
            box-sizing: border-box;
        }

        .history-item-id {
            font-weight: 600;
            color: var(--primary);
            font-size: 17px;
            letter-spacing: -0.022em;
        }

        .history-item-time {
            font-size: 13px;
            color: var(--text-secondary);
            letter-spacing: -0.022em;
        }

        .history-item-details {
            width: 100%;
            display: flex;
            flex-direction: column;
            gap: 6px;
            box-sizing: border-box;
            font-size: 14px;
            color: var(--text-secondary);
            padding: 0 calc(var(--spacing-base) * 0.5);
        }

        .history-item-details > div {
            display: flex;
            align-items: center;
        }

        .history-item-details > div::before {
            content: attr(data-label);
            min-width: 70px;
            margin-right: 8px;
        }

        .adorn-info {
            width: 100%;
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: calc(var(--spacing-base) * 0.75);
            margin-top: var(--spacing-base);
            padding-top: var(--spacing-base);
            border-top: 1px solid var(--border);
            box-sizing: border-box;
            font-size: 13px;
        }

        .history-item-stat {
            display: flex;
            flex-direction: column;
            gap: 4px;
        }

        .history-item-label {
            font-size: 0.9rem;
            opacity: 0.7;
        }

        .history-item-value {
            font-size: 1.1rem;
            font-weight: 600;
            color: var(--secondary);
        }

        .history-item-server {
            display: inline-block;
            padding: 4px 10px;
            background: rgba(255, 255, 255, 0.08);
            border-radius: 6px;
            font-size: 13px;
            margin-top: 12px;
            color: var(--text-secondary);
            letter-spacing: -0.022em;
        }

        .user-info {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            border-radius: var(--radius-base);
            padding: var(--spacing-base);
            margin-top: var(--spacing-base);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .user-info-item {
            display: flex;
            flex-direction: column;
            gap: 4px;
        }

        .user-info-label {
            font-size: 13px;
            color: rgba(255, 255, 255, 0.9);
            letter-spacing: -0.022em;
        }

        .user-info-value {
            font-size: 17px;
            font-weight: 600;
            letter-spacing: -0.022em;
        }

        .snackbar {
            position: fixed;
            top: calc(var(--spacing-base) * 1.25);
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0, 0, 0, 0.8);
            color: var(--text-primary);
            padding: 12px 24px;
            border-radius: var(--radius-base);
            font-size: 15px;
            letter-spacing: -0.022em;
            z-index: 1000;
            opacity: 0;
            visibility: hidden;
            transition: var(--transition);
            backdrop-filter: blur(10px);
            -webkit-backdrop-filter: blur(10px);
            box-shadow: var(--shadow-lg);
        }

        .snackbar.show {
            opacity: 1;
            visibility: visible;
        }

        .icon {
            font-size: 20px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
        }

        @media (max-width: 768px) {
            .main-content {
                padding: calc(var(--spacing-base) / 2);
            }

            .adorn-info {
                grid-template-columns: 1fr;
            }

            .history-tabs {
                gap: 2px;
            }

            .tab-button {
                padding: 6px 8px;
                font-size: 13px;
            }
        }
    </style>
</head>

<body>
    <div class="app-container">
        <header class="header">
            <div class="header-content">
                <a href="index.html" class="logo">
                    🍊 橙子小工具
                </a>
                <h1 class="page-title">橙子身高历史记录查询</h1>
                <div class="header-buttons">
                    <a href="https://qm.qq.com/q/6bX5cgkbL4" target="_blank" class="join-group-btn">
                        加入QQ群
                    </a>
                </div>
            </div>
        </header>

        <main class="main-content">
            <section class="search-section">
                <div class="search-input-container">
                    <input type="text" 
                           class="search-input" 
                           id="userId" 
                           placeholder="请输入用户ID查询历史记录">
                </div>
                <button class="join-group-btn" onclick="window.location.href='index.html'" style="width: 100%; margin-top: 16px;">
                    <span class="icon" style="margin-right: 8px;">⬅️</span>
                    返回首页
                </button>
            </section>

            <section class="history-section">
                <div class="history-tabs">
                    <button class="tab-button active" data-type="all">全部记录</button>
                    <button class="tab-button" data-type="cn">国服记录</button>
                    <button class="tab-button" data-type="live">国际服记录</button>
                    <button class="tab-button" data-type="beta">测试服记录</button>
                </div>
                <div class="history-list" id="historyList">
                    <!-- 历史记录将通过 JavaScript 动态加载 -->
                </div>
            </section>
        </main>
    </div>

    <div class="snackbar" id="snackbar"></div>

    <script src="https://cdn.jsdelivr.net/npm/cos-js-sdk-v5/dist/cos-js-sdk-v5.min.js"></script>
    <script src="js/cos-handler.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', async function() {
            // 绑定事件监听器
            bindEventListeners();
            // 加载历史记录
            await loadHistory();
        });

        // 绑定事件监听器
        function bindEventListeners() {
            // 服务器类型按钮点击事件
            document.querySelectorAll('.server-type-btn').forEach(btn => {
                btn.addEventListener('click', function() {
                    const type = this.getAttribute('data-type');
                    filterHistory(type);
                });
            });
        }

        // 加载历史记录
        async function loadHistory() {
            try {
                const history = await window.cosHandler.getHistory();
                renderHistory(history);
            } catch (error) {
                console.error('加载历史记录失败:', error);
                showMessage('加载历史记录失败，请稍后重试');
            }
        }

        // 渲染历史记录
        function renderHistory(history) {
            const historyList = document.getElementById('historyList');
            if (!historyList) return;

            if (!history || history.length === 0) {
                historyList.innerHTML = '<div class="empty-state">暂无历史记录</div>';
                return;
            }

            historyList.innerHTML = history.map(item => renderHistoryItem(item)).join('');
        }

        // 渲染历史记录项
        function renderHistoryItem(item) {
            if (!item || !item.data || !item.data.data) return '';

            const formattedTime = CosHandler.formatTimestamp(item.timestamp);
            const serverType = {
                'cn': '国服',
                'live': '国际服',
                'beta': '测试服'
            }[item.type] || item.type;

            const queryUser = CosHandler.formatUserId(item.queryUserId);
            const result = item.data.data;
            const adorn = item.data.adorn;

            // 处理装扮信息
            let adornHtml = '';
            if (adorn && Object.keys(adorn).length > 0) {
                adornHtml = Object.entries(adorn)
                    .map(([key, value]) => {
                        // 检查值是否为纯数字
                        const displayValue = /^\d+$/.test(value) ? '未知装扮' : value;
                        return `<div>${CosHandler.getAdornTypeName(key)}: ${displayValue}</div>`;
                    })
                    .join('');
            }

            return `
                <div class="history-item" data-type="${item.type}">
                    <div class="history-item-header">
                        <div class="history-item-id">${item.id}</div>
                        <div class="history-item-time">${formattedTime}</div>
                    </div>
                    <div class="history-item-details">
                        <div data-label="查询者">: ${queryUser}</div>
                        <div data-label="体型值">: ${result.scale || '-'}</div>
                        <div data-label="当前身高">: ${result.currentHeight ? result.currentHeight : '-'}</div>
                    </div>
                    ${adornHtml ? `<div class="adorn-info">${adornHtml}</div>` : ''}
                    <div class="history-item-server">${serverType}</div>
                </div>
            `;
        }

        // 过滤历史记录
        function filterHistory(type) {
            const historyItems = document.querySelectorAll('.history-item');
            historyItems.forEach(item => {
                if (type === 'all' || item.getAttribute('data-type') === type) {
                    item.style.display = 'block';
                } else {
                    item.style.display = 'none';
                }
            });

            // 更新按钮状态
            document.querySelectorAll('.server-type-btn').forEach(btn => {
                btn.classList.toggle('active', btn.getAttribute('data-type') === type);
            });
        }

        // 显示提示消息
        function showMessage(message) {
            const messageDiv = document.createElement('div');
            messageDiv.className = 'message';
            messageDiv.textContent = message;
            document.body.appendChild(messageDiv);

            setTimeout(() => {
                messageDiv.remove();
            }, 3000);
        }
    </script>
</body>
</html> 